NikMik Posted March 11, 2014 Share Posted March 11, 2014 (edited) For William 2, I am making it so when you build the house, you can go inside. It's all working fine apart from one thing: Every time you leave the house, it resets. This is my first attempt, and it's basically all copied from "The Lost Fragment"AddGlobalClassPostConstruct("saveindex", "SaveIndex", function(self)function self:Enterhouse(cb)local function ongamesaved()self.data.slots[self.current_slot].current_mode = "house"self.data.slots[self.current_slot].modes.house = {}-- Hunt through the survival levels and find ours, then save its index.local Levels = require("map/levels")for i,level in ipairs(Levels.custom_levels) doif level.id == "HOUSE" thenself.data.slots[self.current_slot].modes.house.options = {level_id = i}print("Found a house level:",i)breakendendself:Save(cb)endself:SaveCurrent(ongamesaved)endfunction self:Exithouse(cb)local filename = self.data.slots[self.current_slot].modes.house.filelocal function onsavedindex()GLOBAL.EraseFiles(cb, {filename})endself.data.slots[self.current_slot].current_mode = "survival"self.data.slots[self.current_slot].modes.house = {}self:Save(onsavedindex)endend)The Lost Fragment deletes the world and resets it when leaving/entering, which I don't want the house to do.Like I said: This is my first attempt, and I could definitely use a little nu - a ****ing huge push in the right direction. Also, it is possible to give it a custom generation screen? It's not super necessary, but I would like to know if it is. Here is the house so far. I haven't given the door out a model yet, made the walls, or replaced the Maxwell Lights with hanging lights yet. But I'm still happy with how it is so far. Just need to fix it resetting. Edited March 11, 2014 by Mr. Tiddles Link to comment https://forums.kleientertainment.com/forums/topic/32627-stop-a-world-from-being-reset-when-enteredexited/ Share on other sites More sharing options...
squeek Posted March 11, 2014 Share Posted March 11, 2014 Unfamiliar with how the SaveIndex works, but this jumps out to me:local function onsavedindex()GLOBAL.EraseFiles(cb, {filename})end Link to comment https://forums.kleientertainment.com/forums/topic/32627-stop-a-world-from-being-reset-when-enteredexited/#findComment-428720 Share on other sites More sharing options...
NikMik Posted March 11, 2014 Author Share Posted March 11, 2014 Unfamiliar with how the SaveIndex works, but this jumps out to me: local function onsavedindex()GLOBAL.EraseFiles(cb, {filename})endIt did to me, too. Attempting to change it in any way resulted in the old survival world becoming the house. Did for me, at least. Link to comment https://forums.kleientertainment.com/forums/topic/32627-stop-a-world-from-being-reset-when-enteredexited/#findComment-428722 Share on other sites More sharing options...
squeek Posted March 11, 2014 Share Posted March 11, 2014 (edited) Seems like you should use caves as a base; Lost Fragments seemingly based their code on adventure mode (which deletes the adventure save if you fail the adventure).The Enter/LeaveCave functions:function SaveIndex:LeaveCave(onsavedcb) local playerdata = {} local player = GetPlayer() if player then playerdata = player:GetSaveRecord().data playerdata.leader = nil playerdata.sanitymonsterspawner = nil end self.data.slots[self.current_slot].modes.cave.playerdata = nil self.data.slots[self.current_slot].current_mode = "survival" if self.data.slots[self.current_slot].modes.survival then self.data.slots[self.current_slot].modes.survival.playerdata = playerdata end self:Save(onsavedcb)endfunction SaveIndex:EnterCave(onsavedcb, saveslot, cavenum, level) self.current_slot = saveslot or self.current_slot --get the current player, and maintain his player data local playerdata = {} local player = GetPlayer() if player then playerdata = player:GetSaveRecord().data playerdata.leader = nil playerdata.sanitymonsterspawner = nil end level = level or 1 cavenum = cavenum or 1 self.data.slots[self.current_slot].current_mode = "cave" if not self.data.slots[self.current_slot].modes.cave then self.data.slots[self.current_slot].modes.cave = {} end self.data.slots[self.current_slot].modes.cave.files = self.data.slots[self.current_slot].modes.cave.files or {} self.data.slots[self.current_slot].modes.cave.current_level = self.data.slots[self.current_slot].modes.cave.current_level or {} self.data.slots[self.current_slot].modes.cave.world = level or 1 self.data.slots[self.current_slot].modes.cave.current_level[cavenum] = level self.data.slots[self.current_slot].modes.cave.current_cave = cavenum local savename = self:GetSaveGameName("cave", self.current_slot) self.data.slots[self.current_slot].modes.cave.playerdata = playerdata self.data.slots[self.current_slot].modes.cave.file = nil TheSim:CheckPersistentStringExists(savename, function(exists) if exists then self.data.slots[self.current_slot].modes.cave.file = savename end self:Save(onsavedcb) end)end Edited March 11, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32627-stop-a-world-from-being-reset-when-enteredexited/#findComment-428749 Share on other sites More sharing options...
NikMik Posted March 11, 2014 Author Share Posted March 11, 2014 (edited) Seems like you should use caves as a base; Lost Fragments seemingly based their code on adventure mode (which deletes the adventure save if you fail the adventure).The Enter/LeaveCave functions:function SaveIndex:LeaveCave(onsavedcb) local playerdata = {} local player = GetPlayer() if player then playerdata = player:GetSaveRecord().data playerdata.leader = nil playerdata.sanitymonsterspawner = nil end self.data.slots[self.current_slot].modes.cave.playerdata = nil self.data.slots[self.current_slot].current_mode = "survival" if self.data.slots[self.current_slot].modes.survival then self.data.slots[self.current_slot].modes.survival.playerdata = playerdata end self:Save(onsavedcb)endfunction SaveIndex:EnterCave(onsavedcb, saveslot, cavenum, level) self.current_slot = saveslot or self.current_slot --get the current player, and maintain his player data local playerdata = {} local player = GetPlayer() if player then playerdata = player:GetSaveRecord().data playerdata.leader = nil playerdata.sanitymonsterspawner = nil end level = level or 1 cavenum = cavenum or 1 self.data.slots[self.current_slot].current_mode = "cave" if not self.data.slots[self.current_slot].modes.cave then self.data.slots[self.current_slot].modes.cave = {} end self.data.slots[self.current_slot].modes.cave.files = self.data.slots[self.current_slot].modes.cave.files or {} self.data.slots[self.current_slot].modes.cave.current_level = self.data.slots[self.current_slot].modes.cave.current_level or {} self.data.slots[self.current_slot].modes.cave.world = level or 1 self.data.slots[self.current_slot].modes.cave.current_level[cavenum] = level self.data.slots[self.current_slot].modes.cave.current_cave = cavenum local savename = self:GetSaveGameName("cave", self.current_slot) self.data.slots[self.current_slot].modes.cave.playerdata = playerdata self.data.slots[self.current_slot].modes.cave.file = nil TheSim:CheckPersistentStringExists(savename, function(exists) if exists then self.data.slots[self.current_slot].modes.cave.file = savename end self:Save(onsavedcb) end)endI was looking for the cave scripts. Guess it managed to just slip through my mind. I'll take a look at that now. Thank you!EDIT: Using the "exit" one will replace the survival world with the interior of the house like the other code. Using and changing up the cave's "entrance" script causes this: Edited March 11, 2014 by Mr. Tiddles Link to comment https://forums.kleientertainment.com/forums/topic/32627-stop-a-world-from-being-reset-when-enteredexited/#findComment-428752 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now